package com.mercury.swagger.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.VendorExtension;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author mercury
 */
@Configuration
@ConfigurationProperties(prefix = "swagger")
@Data
public class SwaggerProperties {

    private String title;
    private String host;
    private String description;
    private String version;
    private String docs = "v2/api-docs";
    private boolean disable = false;
    private String basePackage = "com.mercury";
    private String termsOfServiceUrl = "https://gitee.com/zc191016@163.com";
    private String contactName = "mercury";
    private String contactEmail = "zc191016@163.com";
    private String contactUrl = "https://gitee.com/zc191016@163.com";
    private Set<StringVendorExtension> stringExtensions = new HashSet<>();


    @SuppressWarnings("rawtypes")
    public List<VendorExtension> getExtensions() {
        List<VendorExtension> result = new ArrayList<>();
        if (null == getStringExtensions()) {
            return result;
        }
        for (StringVendorExtension stringExtension : getStringExtensions()) {
            result.add(new springfox.documentation.service.StringVendorExtension(stringExtension.getName(), stringExtension.getValue()));
        }
        return result;
    }
}

@Data
class StringVendorExtension implements VendorExtension<String> {

    private String name;
    private String value;

}
